<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Session;

class RegionController extends Controller
{
    //送货地区
    public function region()
    {
    	$data = DB::table('region') -> paginate(10);
        // $data = DB::table('user') -> paginate(10); 

    	return view('/admin/order/region/region',['data'=>$data]);
    }

    //编辑送货地区
    public function regionedit($id)
    {
    	$data = DB::table('region') -> where('region_id','=',$id) -> select('region_id','region_name','freight') -> first();
    	// echo $id;
    	// var_dump(($data));
    	// dd($data);
    	return view('/admin/order/region/edit',['data'=>$data]);
    }

    //送货地区更新
    public function regionupdate(Request $request)
    {
    	$data = $request -> except('_token');
    	// dd($data);
    	$res = DB::table('region') -> where('region_id','=',$data['region_id']) -> update($data);
        // dd($res);
    	if($res)
    	{
    		return redirect('admin/region') -> with(['success'=>'更新成功']);
    	}else{
    		return back() -> with(['error'=>'请更新数据']);
    	}
    }

}
